/* eslint-disable */
// 该文件由 OneAPI 自动生成，请勿手动修改！
import {request} from '@umijs/max';
import {headerConfig, responseIntercept} from "@/services/request";
import {OperatingSystem} from "@/utils/enums";
import {getBizBaseUrl, getImBaseUrl} from "@/constants";
import {message} from "antd";
import {ErrorCode, ErrorType} from "@/utils/errCode";

/** 此处后端没有提供注释 GET /api/v1/queryUserList */
export async function queryUserList(
    params: {
        // query
        /** keyword */
        keyword?: string;
        /** current */
        current?: number;
        /** pageSize */
        pageSize?: number;
    },
    options?: { [key: string]: any },
) {
    return request<API.Result_PageInfo_UserInfo__>('/api/v1/queryUserList', {
        method: 'GET',
        params: {
            ...params,
        },
        ...(options || {}),
    });
}

/** 此处后端没有提供注释 POST /api/v1/user */
export async function addUser(
    body?: API.UserInfoVO,
    options?: { [key: string]: any },
) {
    return request<API.Result_UserInfo_>('/api/v1/user', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        data: body,
        ...(options || {}),
    });
}

/** 此处后端没有提供注释 GET /api/v1/user/${param0} */
export async function getUserDetail(
    params: {
        // path
        /** userId */
        userId?: string;
    },
    options?: { [key: string]: any },
) {
    const {userId: param0} = params;
    return request<API.Result_UserInfo_>(`/api/v1/user/${param0}`, {
        method: 'GET',
        params: {...params},
        ...(options || {}),
    });
}

/** 此处后端没有提供注释 PUT /api/v1/user/${param0} */
export async function modifyUser(
    params: {
        // path
        /** userId */
        userId?: string;
    },
    body?: API.UserInfoVO,
    options?: { [key: string]: any },
) {
    const {userId: param0} = params;
    return request<API.Result_UserInfo_>(`/api/v1/user/${param0}`, {
        method: 'PUT',
        headers: {
            'Content-Type': 'application/json',
        },
        params: {...params},
        data: body,
        ...(options || {}),
    });
}

/** 此处后端没有提供注释 DELETE /api/v1/user/${param0} */
export async function deleteUser(
    params: {
        // path
        /** userId */
        userId?: string;
    },
    options?: { [key: string]: any },
) {
    const {userId: param0} = params;
    return request<API.Result_string_>(`/api/v1/user/${param0}`, {
        method: 'DELETE',
        params: {...params},
        ...(options || {}),
    });
}


export async function getUserList(
    pagination: {
        pageNumber: number,
        showNumber: number,
    }
) {
let res =     await getUsers(pagination);
    debugger

    const {data, errCode} = await getUsers(pagination);
    const userIDs = data.users.map(item => item.userID);
    let {data: lines, errCode: lineErrCode} = await getUsersOnlineTokenDetail(userIDs)
    lines = lines || [];
    const linesMap = lines.reduce((map, line) => {
        map.set(line.userID, {...line});
        return map;
    }, new Map());

    const users = data.users.map(user => {
        return {
            ...user, status: linesMap.get(user.userID)
        }
    })
    return {users: users, total: data.total}


}


//  获取用户列表
export async function getUsers(
    pagination: {
        pageNumber: number,
        showNumber: number,
    }
) {
    return request<API.Result_>(`${getImBaseUrl()}/user/get_users`, {
        method: 'POST',
        data: {
            pagination: pagination
        },
        headers: headerConfig(),
        responseInterceptors: [responseIntercept],
    });
}


//  获取用户在线状态
export async function getUsersOnlineTokenDetail(
    userIDs: []
) {
    return request<API.Result_>(`${getImBaseUrl()}/user/get_users_online_token_detail`, {
        method: 'POST',
        data: {
            userIDs
        },
        headers: headerConfig(),
        responseInterceptors: [responseIntercept],

    });
}

//  强制下线
export async function authForceLogout(
    platform: string,
    userID: string
) {
    return request<API.Result_>(`${getImBaseUrl()}/auth/force_logout`, {
        method: 'POST',
        data: {
            "platformID": OperatingSystem[platform],
            "userID": userID
        },
        headers: headerConfig(),
        responseInterceptors: [responseIntercept],
    });
}

//  parseImToken
export async function parseImToken(
    uuid: string,
) {
    return request<API.Result_>(`${getBizBaseUrl()}/user/imUser/parseToken/${uuid}`, {
        method: 'POST'
    });
}
